﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Tradex.ComponentModel;
using Tradex.Trading;

namespace Tradex.Messages {

    /// <summary>
    /// The OrdersUpdateMessage contains a list of active orders for a given account. It originates either in the trading
    /// system towards the user interface of strategies, or in the connector towards the trading system. The amount of
    /// information provided can vary - if no OrderUpdate is given, the consumer must request this information separately.
    /// </summary>
    [Serializable ()]
    public sealed class OrdersUpdateMessage : Message {

        /// <summary>
        /// Public constructor taking all values.
        /// </summary>
        /// <param name="accountKey"></param>
        /// <param name="entries"></param>
        public OrdersUpdateMessage(AccountKey accountKey, IList<Entry> entries) {
            AccountKey = accountKey;
            OrderUpdates = new ReadOnlyIndexer<Entry>(entries);
        }

        /// <inheritdoc />
        public override MessageCode Code { get { return MessageCode.OrderUpdate; } }

        /// <summary>
        /// The AccountKey, identifying the account the orders list is for.
        /// </summary>
        public AccountKey AccountKey { get; private set; }

        /// <summary>
        /// Gets the entries, which contain OrderKey, Orderid and OrderUpdate (if available) for all active orders.
        /// </summary>
        public ReadOnlyIndexer<Entry> OrderUpdates { get; private set; }

        /// <summary>
        /// This inner class is an entry in the order list.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
        public class Entry {

            /// <summary>
            /// Public constructor taking all values.
            /// </summary>
            /// <param name="orderKey"></param>
            /// <param name="orderConnectionKey"></param>
            /// <param name="orderUpdate"></param>
            public Entry(
                OrderKey orderKey,
                OrderId orderConnectionKey,
                OrderUpdate orderUpdate
            ) {
                OrderKey = orderKey;
                OrderConnectionKey = orderConnectionKey;
                OrderUpdate = orderUpdate;
            }

            /// <summary>
            /// Gets the OrderKey.
            /// </summary>
            public OrderKey OrderKey { get; private set; }

            /// <summary>
            /// Gets the OrderId.
            /// </summary>
            public OrderId OrderConnectionKey { get; private set; }

            /// <summary>
            /// Gets the OrderUpdate (if available).
            /// </summary>
            public OrderUpdate OrderUpdate { get; private set; }

        }

    }

}
